# name = "苑昊"
#
# ret01 = name.encode('utf-8')
# print(ret01, type(ret01))
#
# ret02 = ret01.decode("utf-8")
# print(ret02, type(ret02))
#
# ret03 = name.encode('gbk')
# print(ret03, type(ret03))
#
# ret04 = ret03.decode('gbk')
# print(ret04, type(ret04))

# def process_log(path, word):
#     with open(path, encoding="utf8") as f:
#         for line in f:
#             if word.lower() in line.lower():
#                 print(line, end='')
#
# file_path = "log.txt"
# filter_word = "info"
# process_log(file_path, filter_word)
# with open("Target.txt","w") as f_w:
#     with open("Source.txt") as f_r:
#         for line in f_r:
#             if not line.startswith("#"):
#                 continue
#             # print(eval(line.strip("#")))
#             val = eval(line.strip("#"))
#             new_line = f"{line.strip('#').strip()}:{val}\n"
#             f_w.write(new_line)

# def merge_files(f_l, out_f):
#     with open(out_f, mode='w', encoding='utf-8') as f_w:
#         for file_p in f_l:
#             with open(file_p, mode='r', encoding='utf-8') as file_p_r:
#                 # f_w.write(file_p_r.read())
#                 # f_w.write("\n")
#                 # print(file_p_r.name)
#                 f_w.write("=" * 20 + file_p_r.name + "=" * 20 + "\n")
#                 for line in file_p_r:
#                     f_w.write(line)
#                 f_w.write("\n")
#
# files_list = ["Source.txt", "target.txt"]
# out_file = "ST.txt"
# merge_files(files_list, out_file)

def count_word(file_path, word):
    count = 0
    with open(file_path, 'r', encoding='utf-8') as f:
        # test = f.read()
        # print(type(test),test)
        # return f.read().count(word)
        for line in f:
            count += line.count(word)
        return count


fp = "更美好世界.txt"
wd = "世界"
print(count_word(fp, wd))
